package com.sanpu.kxe.business.member.adapter;

import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.member.bean.MemberTeamOutput;
import com.sanpu.kxe.common.interfaces.CommonConfig;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.common.view.ShapeImageView;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;
import com.sanpu.kxe.utils.VerifyUtil;

import java.util.ArrayList;

import static com.sanpu.kxe.R.id.realNameTv;

/**
 * Description：团队列表
 * Created by 薛勇军 on 2019/9/27.
 */

public class MemberTeamAdapter extends BaseQuickAdapter<MemberTeamOutput, BaseViewHolder> {

    private boolean mIsDirect = false;

    public MemberTeamAdapter(boolean isDirect) {
        super(R.layout.item_member_team, new ArrayList<MemberTeamOutput>());
        this.mIsDirect = isDirect;
    }

    @Override
    protected void convert(BaseViewHolder helper, MemberTeamOutput item) {
        if (item != null) {
            helper.setText(R.id.levelNameTv, !TextUtils.isEmpty(item.getLevelName()) ? item.getLevelName() : "")
                    .setText(realNameTv, "姓名：" + item.getRealName())
                    .setText(R.id.registerTimeTv, "注册时间：" + item.getRegisterTime())
                    .setText(R.id.phoneNumberTv, "手机：" + VerifyUtil.secretPhoneNumber(item.getPhoneNumber()))
                    .addOnClickListener(R.id.callTelLl);

            ShapeImageView headPortraitIv = helper.getView(R.id.headPortraitIv);
            if (!TextUtils.isEmpty(item.getHeadPortrait())) {
                JKImageLoader.getInstance().displayImage(mContext,
                        UrlConstants.getBaseUrl() + item.getHeadPortrait(), headPortraitIv);
            }

            TextView chkStsTv = helper.getView(R.id.chkStsTv);
            if (TextUtils.equals(CommonConfig.AUTHEN_PASS, item.getChkSts())) {
                chkStsTv.setText("已认证");
                chkStsTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_1e92ff));
            } else {
                chkStsTv.setText("未认证");
                chkStsTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_959595));
            }

            ImageView directIv = helper.getView(R.id.directIv);
            if (mIsDirect) {
                directIv.setImageResource(R.drawable.ic_member_team_one);
            } else {
                directIv.setImageResource(R.drawable.ic_member_team_two);
            }
        }
    }
}
